package service

import (
	"go_my_framework/app/dao"
)

type ArticleCategoryService struct {
}

func (c *ArticleCategoryService) Add(categoryId int, articleId int) error {
	return dao.NewArticleCategoryDaoImpl().Create(categoryId, articleId)
}

func (c *ArticleCategoryService) GetCateByArticleId(articleId int) []int {
	data := dao.NewArticleCategoryDaoImpl().GetList(articleId)
	list := make([]int, len(data), len(data))
	for k, v := range data {
		list[k] = v.CategoryId
	}
	return list
}

func (c *ArticleCategoryService) UpdateOrAdd(articleId int, categoryId []int) {
	// 删除旧的
	_ = dao.NewArticleCategoryDaoImpl().Del(articleId)

	// 添加新的
	for _, v := range categoryId {
		_ = dao.NewArticleCategoryDaoImpl().Create(v, articleId)
	}
}
